<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试批阅 - 在线考试系统</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/all.min.css">
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --teacher-accent: #4361ee;
            --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fb;
            color: #333;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .navbar {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 0.8rem 1rem;
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            margin-right: 10px;
            font-size: 1.8rem;
        }

        .nav-link {
            color: rgba(255, 255, 255, 0.85) !important;
            font-weight: 500;
            padding: 0.5rem 1rem !important;
            border-radius: 4px;
            margin: 0 3px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
            color: white !important;
        }

        .main-content {
            flex: 1;
            padding: 2rem 0;
        }

        .page-header {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
            position: relative;
            overflow: hidden;
        }

        .page-header::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background-color: var(--teacher-accent);
        }

        .page-title {
            font-weight: 700;
            margin-bottom: 0.5rem;
            color: var(--teacher-accent);
        }

        .page-subtitle {
            color: #6c757d;
            margin-bottom: 0;
        }

        .exam-info {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
        }

        .exam-info h5 {
            color: var(--teacher-accent);
            margin-bottom: 1rem;
        }

        .info-item {
            margin-bottom: 0.5rem;
        }

        .info-item strong {
            color: #495057;
        }

        .question-card {
            background: white;
            border-radius: 15px;
            padding: 2rem;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
            border-left: 5px solid var(--teacher-accent);
        }

        .question-header {
            display: flex;
            justify-content: between;
            align-items: center;
            margin-bottom: 1.5rem;
            padding-bottom: 1rem;
            border-bottom: 1px solid #e9ecef;
        }

        .question-number {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 0.5rem 1rem;
            border-radius: 20px;
            font-weight: 700;
            font-size: 1.1rem;
        }

        .question-type {
            background: #e9ecef;
            color: #495057;
            padding: 0.3rem 0.8rem;
            border-radius: 15px;
            font-size: 0.9rem;
            font-weight: 600;
        }

        .question-content {
            font-size: 1.1rem;
            margin-bottom: 1.5rem;
            line-height: 1.6;
        }

        .answer-section {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 1.5rem;
            margin-bottom: 1.5rem;
        }

        .answer-label {
            font-weight: 700;
            color: #495057;
            margin-bottom: 0.5rem;
        }

        .student-answer {
            background: white;
            border: 2px solid #e9ecef;
            border-radius: 8px;
            padding: 1rem;
            margin-bottom: 1rem;
            min-height: 60px;
        }

        .correct-answer {
            background: #d4edda;
            border: 2px solid #c3e6cb;
            border-radius: 8px;
            padding: 1rem;
            color: #155724;
        }

        .score-section {
            display: flex;
            gap: 1rem;
            align-items: center;
            margin-bottom: 1rem;
        }

        .score-input {
            max-width: 120px;
        }

        .max-score {
            color: #6c757d;
            font-size: 0.9rem;
        }

        .comment-section {
            margin-top: 1rem;
        }

        .btn-submit {
            background: linear-gradient(135deg, var(--teacher-accent), #3a0ca3);
            border: none;
            color: white;
            padding: 0.75rem 2rem;
            border-radius: 8px;
            font-weight: 600;
            transition: var(--transition);
        }

        .btn-submit:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(67, 97, 238, 0.4);
        }

        .footer {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 2rem 0;
            margin-top: auto;
        }

        .footer-title {
            font-weight: 700;
            margin-bottom: 1rem;
            font-size: 1.25rem;
        }

        .footer-links {
            list-style: none;
            padding: 0;
        }

        .footer-links li {
            margin-bottom: 0.5rem;
        }

        .footer-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: var(--transition);
        }

        .footer-links a:hover {
            color: white;
            text-decoration: underline;
        }

        .copyright {
            text-align: center;
            padding-top: 1.5rem;
            margin-top: 1.5rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.7);
            font-size: 0.9rem;
        }

        .total-score {
            background: linear-gradient(135deg, #28a745, #20c997);
            color: white;
            padding: 1rem 1.5rem;
            border-radius: 10px;
            text-align: center;
            margin-bottom: 2rem;
        }

        .total-score h4 {
            margin: 0;
            font-weight: 700;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="/teacher/home">
                <i class="fas fa-chalkboard-teacher"></i>在线考试系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/home/manage"><i class="fas fa-home"></i> 主页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/exam/manage"><i class="fas fa-tasks"></i> 考试管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/teacher/question/manage"><i class="fas fa-book"></i> 题库管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="/exam/pending"><i class="fas fa-edit"></i> 待批改</a>
                    </li>
                </ul>

                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/teacher/profile">
                            <i class="fas fa-user-circle"></i> 个人信息
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/logout">
                            <i class="fas fa-sign-out-alt"></i> 退出登录
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主内容区域 -->
    <div class="main-content">
        <div class="container">
            <div class="page-header">
                <h2 class="page-title"><i class="fas fa-edit me-2"></i>考试批阅</h2>
                <p class="page-subtitle">为学生答题进行评分和评语</p>
            </div>

            <!-- 考试信息 -->
            <div class="exam-info">
                <h5><i class="fas fa-info-circle me-2"></i>考试信息</h5>
                <div class="row">
                    <div class="col-md-6">
                        <div class="info-item">
                            <strong>考试名称：</strong><span th:text="${examReview.examName}">考试名称</span>
                        </div>
                        <div class="info-item">
                            <strong>学生姓名：</strong><span th:text="${examReview.studentName}">学生姓名</span>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="info-item">
                            <strong>课程名称：</strong><span th:text="${examReview.courseName}">课程名称</span>
                        </div>
                        <div class="info-item">
                            <strong>提交时间：</strong><span th:text="${#temporals.format(examReview.submitTime, 'yyyy-MM-dd HH:mm')}">提交时间</span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 总分显示 -->
            <div class="total-score">
                <h4><i class="fas fa-star me-2"></i>预计总分：<span id="totalScore">0</span> 分</h4>
            </div>

            <!-- 答题批阅 -->
            <form id="reviewForm">
                <input type="hidden" id="recordId" th:value="${examReview.recordId}">
                
                <div th:each="answer, stat : ${examReview.answers}" class="question-card">
                    <div class="question-header">
                        <div class="d-flex align-items-center">
                            <span class="question-number" th:text="'第' + ${stat.count} + '题'">第1题</span>
                            <span class="question-type ms-3" th:text="${answer.questionType == 'choice' ? '选择题' : answer.questionType == 'fill' ? '填空题' : '简答题'}">题目类型</span>
                        </div>
                    </div>
                    
                    <div class="question-content" th:text="${answer.questionContent}">题目内容</div>
                    
                    <div class="answer-section">
                        <div class="answer-label">学生答案：</div>
                        <div class="student-answer" th:text="${answer.studentAnswer}">学生答案</div>
                        
                        <div class="answer-label">参考答案：</div>
                        <div class="correct-answer" th:text="${answer.correctAnswer}">参考答案</div>
                    </div>
                    
                    <div class="score-section">
                        <div>
                            <label for="score_${answer.answerId}" class="form-label">得分：</label>
                            <input type="number" class="form-control score-input" 
                                   th:id="'score_' + ${answer.answerId}"
                                   th:name="'score_' + ${answer.answerId}"
                                   th:max="${answer.maxScore}"
                                   th:min="0"
                                   th:step="0.5"
                                   th:value="${answer.score}"
                                   onchange="updateTotalScore()">
                        </div>
                        <div class="max-score">
                            <i class="fas fa-info-circle me-1"></i>满分：<span th:text="${answer.maxScore}">10</span>分
                        </div>
                    </div>
                    
                    <div class="comment-section">
                        <label th:for="'comment_' + ${answer.answerId}" class="form-label">教师评语：</label>
                        <textarea class="form-control" rows="3"
                                  th:id="'comment_' + ${answer.answerId}"
                                  th:name="'comment_' + ${answer.answerId}"
                                  th:text="${answer.teacherComment}"
                                  placeholder="请输入评语（可选）"></textarea>
                    </div>
                </div>
                
                <div class="text-center">
                    <button type="button" class="btn btn-submit" onclick="submitReview()">
                        <i class="fas fa-check me-2"></i>完成批阅
                    </button>
                </div>
            </form>
        </div>
    </div>

<!-- 页脚 -->
<footer class="footer">
    <div class="container text-center py-4">
        <a href="https://gitee.com/sorrymaker04/onlineexam-workload" target="_blank"><i class="fab fa-github fa-2x"></i></a>
        <div class="copyright mt-2">
            &copy; 2025 版权所有 北城在线考试系统小组 12 Team
        </div>
    </div>
</footer>
    <script src="/js/bootstrap.bundle.min.js"></script>
    <script src="/js/jquery.min.js"></script>
    <script>
        // 更新总分
        function updateTotalScore() {
            let total = 0;
            document.querySelectorAll('input[type="number"]').forEach(input => {
                if (input.value) {
                    total += parseFloat(input.value);
                }
            });
            document.getElementById('totalScore').textContent = total.toFixed(1);
        }
        
        // 页面加载时计算总分
        document.addEventListener('DOMContentLoaded', function() {
            updateTotalScore();
        });
        
        // 提交批阅结果
        function submitReview() {
            if (!confirm('确定要提交批阅结果吗？提交后将无法修改。')) {
                return;
            }
            
            const recordId = document.getElementById('recordId').value;
            const answers = [];
            
            // 收集所有答题的分数和评语
            document.querySelectorAll('.question-card').forEach(card => {
                const scoreInput = card.querySelector('input[type="number"]');
                const commentInput = card.querySelector('textarea');
                
                if (scoreInput) {
                    const answerId = scoreInput.name.split('_')[1];
                    answers.push({
                        answerId: parseInt(answerId),
                        score: parseFloat(scoreInput.value) || 0,
                        teacherComment: commentInput ? commentInput.value : ''
                    });
                }
            });
            
            const reviewData = {
                recordId: parseInt(recordId),
                answers: answers
            };
            
            $.ajax({
                url: '/exam/review/submit',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(reviewData),
                success: function(response) {
                    if (response.success) {
                        alert('批阅完成！');
                        window.location.href = '/exam/pending';
                    } else {
                        alert('批阅失败：' + response.message);
                    }
                },
                error: function() {
                    alert('提交失败，请重试');
                }
            });
        }
    </script>
</body>
</html> 